<html>
<head>
<title>MainActivity.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: #999999; font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { color: rgb(0,0,0); }
.s2 { color: rgb(128,128,128); font-style: italic; }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#c0c0c0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
MainActivity.java</FONT>
</center></TD></TR></TABLE>
<pre>
<span class="s0">package </span><span class="s1">com.hnevc.androidui5; 
 
</span><span class="s0">import </span><span class="s1">android.support.v7.app.AppCompatActivity; 
</span><span class="s0">import </span><span class="s1">android.os.Bundle; 
</span><span class="s0">import </span><span class="s1">android.view.View; 
</span><span class="s0">import </span><span class="s1">android.widget.Button; 
</span><span class="s0">import </span><span class="s1">android.widget.TextView; 
 
</span><span class="s0">public class </span><span class="s1">MainActivity </span><span class="s0">extends </span><span class="s1">AppCompatActivity { 
Button mBtnCompute; 
TextView mTvMessage;</span><span class="s2">//显示message的文本框</span><span class="s1"> 
    @Override 
    </span><span class="s0">protected void </span><span class="s1">onCreate(Bundle savedInstanceState) { 
        </span><span class="s0">super</span><span class="s1">.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
 
        initView(); 
        initEvent(); 
 
    } 
    </span><span class="s2">//声明一个接口，这个接口将会把message的信息显示到Activity</span><span class="s1"> 
</span><span class="s0">interface </span><span class="s1">onComputed{ 
        </span><span class="s0">void </span><span class="s1">showMessage(String message); 
 
} 
    </span><span class="s0">private void </span><span class="s1">initEvent() { 
        </span><span class="s2">//绑定事件</span><span class="s1"> 
mBtnCompute.setOnClickListener(</span><span class="s0">new </span><span class="s1">View.OnClickListener() { 
    @Override 
    </span><span class="s0">public void </span><span class="s1">onClick(View v) { 
 
        </span><span class="s2">//显示对话框</span><span class="s1"> 
        MyDialog dialog= </span><span class="s0">new </span><span class="s1">MyDialog(MainActivity.</span><span class="s0">this</span><span class="s1">, </span><span class="s0">new </span><span class="s1">onComputed() { 
            @Override 
            </span><span class="s0">public void </span><span class="s1">showMessage(String message) { 
                mTvMessage.setText(message); 
            } 
        }); 
        dialog.show(); 
 
    } 
}); 
    } 
 
    </span><span class="s0">private void </span><span class="s1">initView() { 
mBtnCompute=findViewById(R.id.btn_buton1);</span><span class="s2">//获取按钮</span><span class="s1"> 
        mTvMessage=findViewById(R.id.tv_message);</span><span class="s2">//获取文本框tv_message</span><span class="s1"> 
 
    } 
} 
</span></pre>
</body>
</html>